import { message } from 'antd';
import { fetchShopList,fetchCoach,saveSchedule,selectAllCourse,querySiteInfoListByVenueIdNotPage,classTableInfoList } from './service';
import { history } from 'umi';

const Model = {
  namespace: 'cubePrivate',
  state: {
    shopList:[],
    coachList:[],
    siteList:[],
    courseList:[],
    classTableInfoList:[]
  },
  effects: {
    *fetchShopList({ payload }, { call,put }) {
      let result=yield call(fetchShopList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            shopList:result.data          }
        });
      }else{
        message.error(result.message);
      }
    },
    *fetchCoach({ payload }, { call,put }) {
      let result=yield call(fetchCoach, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            coachList:result.data
          }
        });
      }else{
        message.error(result.message);
      }
    },
    *saveSchedule({ payload }, { call,put }) {
      let result=yield call(saveSchedule, payload);
      if(result.code===0){
        message.success('添加成功');
        history.push(`/lesson/private`);
      }else{
        message.error(result.message);
      }
    },
    *querySiteInfoListByVenueIdNotPage({ payload }, { call,put }) {
      let result=yield call(querySiteInfoListByVenueIdNotPage, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            siteList:result.data
          }
        });
      }else{
        message.error(result.message);
      }
    },
    *selectAllCourse({ payload }, { call,put }) {
      let result=yield call(selectAllCourse, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            courseList:result.data
          }
        });
      }else{
        message.error(result.message);
      }
    },
    *classTableInfoList({ payload }, { call,put }) {
      let result=yield call(classTableInfoList, payload);
      if(result.code===0){
        yield put({
          type: 'common',
          payload: {
            classTableInfoList:result.data
          }
        });
        return result.data
      }else{
        message.error(result.message);
      }
      return []
    },
  },
  reducers: {
    common(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
export default Model;
